package com.example.springcloud.gateway.config;

import org.springframework.cloud.gateway.route.RouteLocator;
import org.springframework.cloud.gateway.route.builder.RouteLocatorBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author Holinc
 * @date 2023/3/29 16:30
 */
@Configuration
public class GatewayConfiguration {

    /**
     * 方式一：application.yml文件配置，spring.cloud.gateway.routes. <br/>
     * 方式二：@Bean的代码方式. <br/>
     *
     * @param builder
     * @return
     */
    @Bean
    public RouteLocator customRouteLocator(RouteLocatorBuilder builder) {
        return builder.routes()
                .route("job", r -> r
                        .path("/job/**")
                        .filters(f -> f.stripPrefix(1))
                        .uri("lb://cloud-provider-job"))
                .build();
    }
}
